/*
 * @Author: wwssaabb
 * @Date: 2021-11-20 16:18:20
 * @LastEditTime: 2021-11-20 17:53:37
 * @FilePath: \handwritten-code\test\test1.js
 */

//打印 1 ~ 10000 之间的对称数，例如 121 1331

let r = []
//暴力解法1
for (let i = 1; i <= 10000; i++) {
  let s = i.toString()
  let l = s.length
  if (l === 1) r.push(i);
  if (l === 2 || l === 3) {
    if (s[0] === s.slice(-1)) r.push(i)
  } else if (l === 4 || l === 5) {
    if (s.slice(0, 2) === s.slice(-2).split('').reverse().join('')) r.push(i)
  }
}

//暴力解法二  
for (let i = 1; i <= 10000; i++) {
  let arr = i.toString().split('')
  let l = arr.length
  let res = []
  if (l === 1) {
    r.push(i)
    continue
  }
  while (arr.length > 1) {
    res.push(arr.shift() === arr.pop())
  }
  res.every(i => i === true) ? r.push(i) : null
}

//暴力解法3 ，对称数逆序还是自己
for (let i = 1; i <= 10000; i++) {
  let str = i.toString()

  function isSym(s) {
    return s === s.split('').reverse().join('')
  }
  str.length === 1 || isSym(str) ? r.push(i) : null
}


//装东西法 ,先有基本对称数 1~9,11~99， 一个对称数两边加上对称的数还是对称数

let arr = [] //基本对称数
for (let i = 0; i <= 9; i++) {
  arr.push(i + '')
  arr.push(i + '' + i)
}
let res = [...arr]
for (let i = 1; i <= 9; i++) {
  arr.forEach(s => res.push(i + s + i))
}
res.shift()
res.shift()
console.log(res)